<!DOCTYPE html>
<html lang="zh">
<head>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>摇一摇-进行中</title>
    <link href="css/main.css" rel="stylesheet" type="text/css"/>
</head>
<body id="yyy-jxz">
    <div class="container">
        <div class="bk-01">
            <p class="ranking">倒计时3: <span>0</span>秒</p>
            <div class="val">

                <div class="num-wrap">
                    <p class="num">0</p>
                    <p class="time">当前次数</p>

                </div>
                <div class="prestrain"><img src="images/shark/start.png" /></div>
                <audio  class="music" preload="metadata"  controls src="music/xianjin.mp3" ></audio>
                <audio  class="music-loding" preload="metadata"  controls src="music/timer.mp3"  ></audio>
                <div class="voice"></div>
            </div>

            <p class="look">查看当前排名</p>
        </div>
        <div class="bk-02">
            当前参与：<span>200</span>人
        </div>

        <!--结果层-->

        <div class="lay-box">
            <div class="yyy-layjxz">
                <div class="content">
                    <div class="hd">
                        <div class="panel">
                            <h4>一共摇了 <span>1234</span> 次 </h4>
                            <p>排在第 <span>3</span> 名 </p>
                        </div>
                        <div class="table-hd">
                            <span>当前排名</span>

                            <span>次数</span>
                        </div>
                    </div>
                    <ol class="bd">
                        <li>
                            <p class="nick-name">用户名用户名</p>
                            <p class="time">99999</p>
                        </li>
                        <li>
                            <p class="nick-name">用户名用户名</p>
                            <p class="time">99999</p>
                        </li>
                        <li>
                            <p class="nick-name">用户名用户名</p>
                            <p class="time">99999</p>
                        </li>
                        <li>
                            <p class="nick-name">用户名用户名</p>
                            <p class="time">99999</p>
                        </li>
                        <li>
                            <p class="nick-name">用户名用户名</p>
                            <p class="time">99999</p>
                        </li>

                    </ol>
                    <div class="btns">
                        <div class="ybtn">关闭排名</div>
                        <!--div class="nybtn">不摇了！就这结果！</div>-->
                    </div>

                </div>
            </div>
            <div class="shade"></div>
        </div>
        <!--预加载-->
        <div class="loding-box">

            <img class="djs-01 heart" src="images/shark/djs-01.png" />
            <img class="djs-02 heart" src="images/shark/djs-02.png" />
            <img class="djs-03 heart" src="images/shark/djs-03.png" />
        </div>
    </div>

    <script src="js/rem.js"></script>
    <script src="js/jquery.js"></script>
    <script src="js/shake.js"></script>
    <script>
        $(function () {
            var prestraintimer=null;
            var prestrainNum=3;
            /*function start(cb) {
                $(".prestrain").on("click",function () {
                    var $self=$(this)
                    prestraintimer = setInterval(function () {
                        if(prestrainNum<=0) {
                            clearInterval(prestraintimer)
                            $(".prestrain").hide()
                            cb()
                        }

                        $self.text("准备"+(prestrainNum--) +"秒开始")

                    },1000)

                })
            }*/


            var $layBox=$(".lay-box");


            var tm=0;
            var $num =$(".num");
            var $music =$(".music");
            var $musicLoding =$(".music-loding");
            var $voice =$(".voice");

            var $timer = $(".timer");
            var $ranking = $(".ranking").find("span");
            var t=20; //时间戳 秒

            function start(cb) {
                $(".prestrain").on("click",function () {
                    var $self=$(this)
                    $(".loding-box").fadeIn()
                    $musicLoding[0].play()
                   /* alert($musicLoding[0].readyState);
                    alert($musicLoding[0].duration);*/
                    $music[0].play();
                    $music[0].pause();
                    prestraintimer = setInterval(function () {
                        $(".djs-0"+(prestrainNum--)+"").fadeOut()
                        if(prestrainNum<=0) {
                            clearInterval(prestraintimer)
                            $(".prestrain").hide()
                            $(".loding-box").hide()
                            cb()
                        }

                    },1000)

                })
            }
            function timer(countDown) {

                var h=parseInt(countDown/(60*60));
                var m=parseInt(countDown/60%60);
                var s=parseInt(countDown%60);

                return {
                    h:h<10 ? "0"+h : h,
                    m:m<10 ? "0"+m : m,
                    s:s<10 ? "0"+s : s
                }
            }
            $ranking.text(t)

            var myShakeEvent = new Shake({
                threshold: 10,
                timeout: 30
            });
            $voice.on("click",function () {
                if( $(this).hasClass("close")){
//                    $music[0].play();
                    $music[0].muted=false;
                    $(this).removeClass("close")
                }else{
//                    $music[0].pause();
                    $music[0].muted=true;
                    $(this).addClass("close")
                }

            });
            $layBox.find(".shade").on("click",function (e) {
                e.stopPropagation()
                $layBox.fadeOut()
                $("body").removeClass("limit")
            })

            start(function () {
                $(".num-wrap").addClass("start")
                myShakeEvent.start();
//                $music[0].load();
//                $music[0].play()
                window.addEventListener('shake', function () {
                    $num.text(++tm);
                    $music[0].play();

                }, false);

                var ltime = setInterval(function(){
                    t--;
                    if(t <=0){
                        clearInterval(ltime)
                    }
                    $ranking.text(t)
                },1000)
            });



            $(".look").on("click",function () {
                $layBox.fadeIn();
                $("body").addClass("limit")
//                $("html").addClass("limit")
            })
            






        })
    </script>
</body>
</html>